var User = require('../../app/controller/user');
var Mp3 = require('../../app/controller/mp3');
var Blog = require('../../app/controller/blog')
var Comment = require('../../app/controller/comment')

var multer  = require('multer')
var upload = multer({ dest: 'public/upload/' })

module.exports = function(app) {

    app.use(function(req, res, next) {
        var _user = req.session.user;
        app.locals.user = _user;
        next();

    });

    //首页
    app.get('/', User.index)



    //注册页面
    app.get('/signup', User.signup);
    //保存用户
    app.post('/signup', User.save);

    //登陆页
    app.get('/signin', User.signin);
    //登陆功能
    app.post('/signin', User.login);

    //登出功能
    app.get('/logout', User.logout);

    //查看blog
    app.get('/blog', Blog.fetch)
    //Blog详情
    app.get('/single/:id', Blog.findOne);

    //提交评论
    app.post('/comment',User.signinRequired,Comment.save);


    //个人设置页
    app.get('/profile',User.signinRequired, User.profile);


    app.get('/test',function(req,res){
      res.render('pages/test')
    })
    app.post('/test',function(req,res){
         console.log(req.body.a)
         res.render('pages/test')
    })
    /**
     * 关于我们
     */
    app.get('/about', function(req, res) {
        res.render('pages/about');
    });
    app.get('/events', function(req, res) {
        res.render('pages/events');
    });

    app.get('/timeline', function(req, res) {
        res.render('pages/timeline');
    });
    /**
     * mv
     */
    app.get('/video', function(req, res) {
        res.render('pages/video');
    });
    /**
     * mv详情
     */
    app.get('/video-detail', function(req, res) {
        res.render('pages/video-detail');
    });

    app.post('/profile',User.signinRequired,upload.single('face'),User.update)
}
